<?php
namespace app\traits;

trait ModelTrait
{
    protected $_vars;

    public static $error;

    public function getLastError()
    {
        if (!empty(static::$error)) {
            return static::$error;
        }
        $errors = $this->getMessages(false);
        while (is_array($errors)) {
            $errors = array_pop($errors);
        }
        static::$error = $errors;
        return static::$error;
    }

    public function __set($name, $value)
    {
        // TODO: Implement __set() method.
        $this->_vars[$name] = $value;
    }

    public function __get($name)
    {
        // TODO: Implement __get() method.
        return $this->_vars[$name] ?? $this->_vars[$name];
    }
}